from collections import Iterable
# print(isinstance([], Iterable))
class Mylist(object):
    def __init__(self):
        self.items=[]
    def add(self,item):
        self.items.append(item)
    def __iter__(self):
        myiterator =MyIterator(self)
        return myiterator

class MyIterator(object):
    '''自定义的供上边的可迭代对象使用的一个迭代器'''
    def __init__(self,mylist):
        self.mylist =mylist
        # 记录当前访问到的位置
        self.current =0
    def __next__(self):
        if self.current <len(self.mylist.items):
            item =self.mylist.items[self.current]
            self.current+=1
            return item
        else:
            raise StopIteration
    def __iter__(self):
        return self


mylist =Mylist()
mylist.add(1)
mylist.add(2)
mylist.add(3)

for i in mylist:
    print(i)